package com.huawei.control.order;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.huawei.bean.Address;
import com.huawei.model.OrderModel;
import com.huawei.utils.EasyFactory;
import com.huawei.utils.MyUtils;

/**
 * Servlet implementation class AddressSavingControl
 */
@WebServlet("/AddressSavingControl")
public class AddressSavingControl extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddressSavingControl() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("进入AddressSavingControl");
		// 将request中的form表单中的数据转换到实体类中
				Address addressB = MyUtils.convertRequest2BeanWithFileUpload(request, Address.class);
				System.out.println(addressB);
				
				// 调用Model层进行用户信息保存的业务逻辑处理
				int i = 1;
				i= EasyFactory.getNewInstance(OrderModel.class).UpdateAddressB(addressB);
				System.out.println("iiii"+i);
				
				// 根据业务逻辑处理结果，进行结果页面的转发处理
				if(i >0) {
					// 新增成功
					// 返回响应内容
					System.out.println("成功了");
					request.getRequestDispatcher("WEB-INF/pages/HWSC/orderQuery.jsp").forward(request, response);
				}else {
					// 新增失败
					System.out.println("失败了");
					request.getRequestDispatcher("WEB-INF/pages/HWSC/orderModify.jsp").forward(request, response);
				}
	}

}
